﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.ComponentModel;
using System.Diagnostics;
using System.Data.SqlClient;


//using MyWeb.DataAccessHelper;
//namespace MyWeb.DataAccessLayer
//{
public class seleData
{
    Datacon dataconn = new Datacon();
    Datacommand datacom = new Datacommand();

    
    public string chasheng(string weixinhao)//查省名称
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select   NAME from CODE_REGION where substring(CODE,3,7)='0000000' and substring(code,1,2)='"+weixinhao.Substring(0,2)+"'";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "";
        //WriteLog("执行完成" + sql);

        while (reader.Read())
        {
            jieguo = reader["NAME"].ToString() + " ";
        }
        cn.Close();
        return jieguo;
    }
    public string chashi(string weixinhao)//查市名称
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select   NAME from CODE_REGION where substring(CODE,5,5)='00000' and substring(code,1,4)='" + weixinhao.Substring(0, 4) + "'";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "";
        //WriteLog("执行完成" + sql);

        while (reader.Read())
        {
            jieguo = reader["NAME"].ToString() + " ";
        }
        cn.Close();
        return jieguo;
    }
    public string chaqu(string weixinhao)//查区名称
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select   NAME from CODE_REGION where substring(CODE,7,3)='000' and substring(code,1,6)='" + weixinhao.Substring(0, 6) + "'";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "";
        //WriteLog("执行完成" + sql);

        while (reader.Read())
        {
            jieguo = reader["NAME"].ToString() + " ";
        }
        cn.Close();
        return jieguo;
    }
    public string chadanwei(string weixinhao)//查单位名称
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select   mingcheng from juming where id=" + weixinhao ;
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "";
        //WriteLog("执行完成" + sql);

        while (reader.Read())
        {
            jieguo = reader["mingcheng"].ToString() ;
        }
        cn.Close();
        return jieguo;
    }

    public string chaname(string weixinhao,string dw)//查最新名字
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select   lxr from lianxijilu where danweiid in (select id from danwei where diquhao='" + weixinhao + "' and juhao=" + dw + ") order by id desc";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "";
        //WriteLog("执行完成" + sql);

        if (reader.Read())
        {
            jieguo = reader["lxr"].ToString();
        }
        cn.Close();
        return jieguo;
    }
    public string chalxjl(string mingzhi)//查今天联系记录
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select c.NAME as name,d.mingcheng as mingcheng from lianxijilu a,danwei b,CODE_REGION c,juming d where a.danweiid=b.id  and b.diquhao=c.CODE and d.id=b.juhao and a.riqi>getdate()-1 and a.jbr='" + mingzhi + "'";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "联系";
        //WriteLog("执行完成" + sql);

        while (reader.Read())
        {
            jieguo = jieguo +"   " + reader["name"].ToString().Trim() + " " + reader["mingcheng"].ToString().Trim();
        }
        cn.Close();
        return jieguo;
    }
    public string chadianhua(string weixinhao,string dw)//查最新电话
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select   dh from lianxijilu where danweiid in (select id from danwei where diquhao='" + weixinhao + "' and juhao=" + dw + ") order by id desc";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "";
        //WriteLog("执行完成" + sql);

        if (reader.Read())
        {
            jieguo = reader["dh"].ToString();
        }
        cn.Close();
        return jieguo;
    }



}

